
console.log("---------------------------- t2.js haha ----------------------------")

//----------------------- 类 --------------------------------
let rb = class {
    constructor(name, url) {
        this.name = name
        this.url = url
    }
}
console.log("class rb name:", rb.name)

class rb222 {
    constructor(name, url) {
        this.name = name
        this.url = url
    }
    age(x) {
        return x - this.year
    }
}
var rb2 = new rb222("nnhy", "http://fflr.com")
rb2.year = 2013
console.log("class rb2 name:", rb2.name, " age:", rb2.age((new Date).getFullYear()))


//----------------------- 类继承 --------------------------------
class Site {
    constructor(name) {
        this.name = name
    }
}
class Runoob extends Site {     // 类继承使用 extends 关键字
    constructor(name, age) {
        super(name)             //super() 方法用于调用父类的构造函数    ES6 
        this.age = age
    }
    show() {
        console.log(this.name + "已" + this.age + "年了！")
    }
}
{
    let ro = new Runoob("菜鸟教程", 5)
    ro.show()
}

//使用原型链继承
function Animal(name) {
    this.name = name
}
Animal.prototype.eat = function () {
    console.log(this.name + " is eating!")
}

function Dog(name, breed) {
    Animal.call(this, name)     //call参考
    this.breed = breed
}

//prototype 使用 Object.create(Animal.prototype) 来创建一个新对象，它继承了 Animal.prototype 的方法和属性
Dog.prototype = Object.create(Animal.prototype)
//prototype.constructor 设置为 Dog，确保继承链上的构造函数正确
Dog.prototype.constructor = Dog
Dog.prototype.bark = function () {
    console.log(this.name + " is barking!")
}

var dog = new Dog("hbg", "mki90")
dog.bark()

//getter 和 setter
class Runoob2 {
    constructor(name) {
        this.name = name
    }
    get s_name() {
        return this.name
    }
    set s_name(name) {
        this.name = name
    }
    //静态方法
    static hello() {
        console.log("hello " + this.name)
    }
    static hello2(x) {
        console.log("hello " + x)
    }
}

//函数声明和类声明之间的一个重要区别在于, 函数声明会提升，类声明不会
f1()
function f1() {
    console.log("f1")
}

{
    let rb2 = new Runoob2("菜鸟2")
    console.log("class rb2:", rb2.s_name)   //想获取属性值时也不要使用括号
    rb2.s_name = "菜鸟22"
    console.log("class rb2:", rb2.s_name)

    Runoob2.hello()
    //rb2.hello()           // 不能通过实例化后的对象调用静态方法
    Runoob2.hello2("bbt")
}

//0o八进制 0x十六
console.log(123e-2, 0o22, 0x33, Infinity)
{
    var n = 128
    console.log(n.toString(), n.toString(16))
}
{
    var n = 2
    console.log("---2 is Nan?:", isNaN(n), isNaN(2 / "ggy"),
        "\n---typeof n:", typeof (n), typeof (new Number(n)), n == new Number(n),
        "\n---n max:", Number.MAX_VALUE, Number.MIN_VALUE, Number.EPSILON, Number.MAX_SAFE_INTEGER,
        "exp:", n.toExponential(), n.toFixed(3))
    for (; n != Infinity;) {
        n *= n
        console.log("---- n:", n)
    }
    console.log("str:", "ss hy ui".replace("hy", "tt"), "gty6".valueOf())

    var ts = "a,1,4,r,gg"
    console.log("ts:", ts.split(","), Math.LOG2E, Math.round(2.5))
    //console.log("dsi92 s d "as" dsd9")
    //Date()
}
{
    var str = "Is this all there is"
    var pt = new RegExp("is", "gi") //g全局搜索 i不区分大小写

    //test()方法搜索字符串指定的值，根据结果并返回真或假
    console.log("str.match: ", str.match(pt), pt.test(str))

    //exec() 方法检索字符串中的指定值。返回值是被找到的值。如果没有发现匹配，则返回 null
    console.log("str exec:", pt.exec("gfgrt56 ue 565 is 6"))
}

//document.write("ass435")


console.log("---------------------------- import t1.js begin ----------------------------")
//引用其它模块
//import './a.js'
import { a_show, userObj } from './t1.js'
import { acars } from './t1.js'
import { myObject } from './t1.js'
import mm from './t1.js'     //names
{
    a_show("44rr")
    a_show(acars)
    a_show(myObject)
    //a_show(aobj.cars)
    a_show(userObj.getName(), userObj.show())
    a_show(mm)
    //userObj.id = 3333
    a_show(userObj.id)
}
console.log("---------------------------- import t1.js end ----------------------------")


console.log("---------------------------- t2.js 88 ----------------------------")
